package com.fernfx.xingtan.my.presenter;

import com.fernfx.xingtan.common.base.BaseIRequestCallback;
import com.fernfx.xingtan.common.base.BaseView;
import com.fernfx.xingtan.common.network.entity.NetworkOKResult;
import com.fernfx.xingtan.my.contract.MyBackCardsListContract;
import com.fernfx.xingtan.my.entity.MyBackCardsListEntity;
import com.fernfx.xingtan.my.model.MyBackCardsListModel;
import com.fernfx.xingtan.utils.FastJsonUtil;
import com.fernfx.xingtan.utils.LogUtils;
import com.fernfx.xingtan.utils.OtherUtil;
import com.fernfx.xingtan.utils.ToastUtil;

import java.util.Map;

/**
 * Created by admin on 2018/8/20.
 */

public class MyBackCardsListPresenter<P extends MyBackCardsListContract.View> extends BaseIRequestCallback implements MyBackCardsListContract.Presenter{
    private P P;
    private MyBackCardsListContract.Model model;

    @Override
    public void init(BaseView view) {
        this.P = (P)view;
        this.model = new MyBackCardsListModel();
    }

    @Override
    public void request(Map<String, Object> requestArgsMap) {
        P.getActivity().showLoading();
        model.request(requestArgsMap,this);
    }

    @Override
    public void detachView() {
        if (model == null) {
            model = null;
        }
    }

    @Override
    public void onSuccessful(NetworkOKResult result) {
        P.getActivity().hideLoading();
        String message =result.getMessage();
        MyBackCardsListEntity myBackCardsListEntity = FastJsonUtil.fromBean(message, MyBackCardsListEntity.class);
        if (OtherUtil.checkRequestStatus(myBackCardsListEntity)) {
            P.showBackCardsList(myBackCardsListEntity.getObj());
        }else {
            ToastUtil.showCentertoast(myBackCardsListEntity.getMsg());
        }
    }
}
